<template>
  <a-dropdown v-if="currentUser" placement="bottomRight">
    <span class="ant-pro-account-avatar">
      <!-- <a-avatar size="small" src="https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png" class="antd-pro-global-header-index-avatar" /> -->
      <a-icon theme="outlined" type="user" :style="{ fontSize: '16px', marginRight: '5px' }"></a-icon>
      <span>{{ currentUser.real_name || currentUser.user_name }}</span>
    </span>
    <template v-slot:overlay>
      <a-menu class="ant-pro-drop-down menu" :selected-keys="[]">
        <a-menu-item v-if="menu" key="settings" @click="handleToSettings">
          <a-icon theme="outlined" type="setting" />账户设置
        </a-menu-item>
        <!-- <a-menu-divider v-if="menu" /> -->
        <a-menu-item key="logout" @click="handleLogout">
          <a-icon theme="outlined" type="logout" />退出登录
        </a-menu-item>
      </a-menu>
    </template>
  </a-dropdown>
  <span v-else>
    <a-spin size="small" :style="{ marginLeft: 8, marginRight: 8 }" />
  </span>
</template>

<script lang="ts" setup>
import { useGo } from '@/hooks/web/usePage'
import { LogoutEmitter } from '@/utils/logoutEmitt'
const go = useGo()
defineProps({
  currentUser: {
    type: Object,
    default: () => null,
  },
  menu: {
    type: Boolean,
    default: true,
  },
})

const handleToSettings = () => go({ path: '/manage/renew' })
const handleLogout = () => LogoutEmitter.emit('logout')
</script>
<script lang="ts">
import { defineComponent } from 'vue'
defineComponent({
  name: 'AvatarDropdown',
})
</script>

<style lang="less" scoped>
.ant-pro-drop-down {
  v-::deep .action {
    padding: 0px 24px;
  }

  v-::deep .ant-dropdown-menu-item {
    min-width: 130px;
    padding-left: 20px;
    font-size: 13px;
  }
}
</style>
